/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uk.ac.bath.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JPanel;
import javax.swing.Timer;
import uk.ac.bath.environment.GuiUpdaterIF;

/**
 *
 * @author pjl
 */
public class GuiUpdater implements GuiUpdaterIF {

    JPanel panel;
    private int delay = 50;

    // public abstract void setDebug(boolean selected);
    private boolean dirty = false;
    Timer t;

    private GuiUpdater() {


        t = new Timer(delay, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                if (dirty) {
                    panel.repaint();
                }
            }
        });

        t.setRepeats(true);
        t.setCoalesce(true);
        t.start();

    }

    public GuiUpdater(JPanel panel) {
        this();
        this.panel = panel;
    }

    public void myUpdate() {
        dirty = true;
    }

//    @Override
//    final public void paint(Graphics g) {
//        super.paint(g);
//        myPaint(g);
//        dirty=false;
//    }
//
//    protected abstract void myPaint(Graphics g);
    public void dispose() {
        t.stop();
        t = null;
    }
}
